#include "graph.h"
#include <bits/stdc++.h>

constexpr int maxN = 201;

int tot, D[maxN], fa[maxN], dep[maxN], dist[maxN];
int ch[maxN][maxN], pdp[maxN][maxN], ans[maxN];
bool p[maxN][maxN], G[maxN][maxN];

void DFS1(int u, int prt) {
  dep[u] = dep[prt] + 1;
  fa[u] = prt, D[u] = NumberOfRoads();
  for (int i = 1; i <= D[u]; i++) {
    Move(i, 2);
    int lst = LastRoad(), col = Color();
    if (col == 1) {
      int v = ++tot;
      DFS1(v, u), ch[u][i] = v;
      G[u][v] = G[v][u] = true;
      p[v][lst] = false;
      col = 3;
    } else if (col == 2) {
      p[u][i] = true;
    }
    Move(lst, col);
  }
}

void DFS2(int u, int base) {
  int col = dep[u] / base % 3 + 1;
  for (int i = 1; i <= D[u]; i++) {
    if (!ch[u][i] && !p[u][i]) { continue; }
    Move(i, col);
    int lst = LastRoad();
    if (ch[u][i]) {
      DFS2(ch[u][i], base);
    } else if (p[u][i]) {
      pdp[u][i] += base * (Color() - 1);
    }
    Move(lst, Color());
  }
}

void Link(int u, int to) {
  assert(to < dep[u]);
  int v = u;
  while (dep[v] > to) { v = fa[v]; }
  G[u][v] = G[v][u] = true;
}

void Inspect(int R) {
  DFS1(tot = 1, 0);
  for (int i = 0, base = 1; i < 5; i++, base *= 3) { DFS2(1, base); }
  for (int i = 1; i <= tot; i++) {
    for (int j = 1; j <= D[i]; j++) {
      if (p[i][j]) { Link(i, pdp[i][j]); }
    }
  }
  for (int i = 1; i <= tot; i++) {
    std::fill(dist + 1, dist + tot + 1, -1);
    std::queue<int> que;
    que.emplace(i), dist[i] = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int v = 1; v <= tot; v++) {
        if (G[u][v] && dist[v] == -1) {
          dist[v] = dist[u] + 1, que.emplace(v);
        }
      }
    }
    for (int j = 1; j <= tot; j++) { ans[dist[j]]++; }
  }
  for (int i = 1; i <= R; i++) { Answer(i, ans[i] / 2); }
}